﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using MyspaceToolkit.OAuth;
using MyspaceToolkit;
using System.Text;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //OAuthBase OAuth1 = new OAuthBase();
        //Uri url1 = new Uri("http://api.msappspace.com/v1/users/30344243.xml");
        //string nonce = System.Guid.NewGuid().ToString();
        //string timestamp = OAuth1.GenerateTimeStamp();
        //string str1 = OAuth1.GenerateSignature(url1, "http://www.myspace.com/329303884", "0a8102bd0e3c424ba3eef5ef1e43cd96", "", "", "GET", timestamp, nonce, OAuthBase.SignatureTypes.HMACSHA1);
        //Response.Redirect("http://api.msappspace.com/v1/users/30344243.xml?oauth_consumer_key=" + OAuth1.UrlEncode("http://www.myspace.com/329303884") + "&oauth_nonce=" + nonce + "&oauth_signature=" + OAuth1.UrlEncode(str1) + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + timestamp + "&oauth_token=&oauth_version=1.0");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        HttpPostUtility poster = new HttpPostUtility();
        HttpPostUtility.MyspaceRequest requestObj = new HttpPostUtility.MyspaceRequest();
        string returnStr = "";

        requestObj.APIversion = "v1";
        requestObj.AssetID = "";
        requestObj.BaseApiUrlHost = "api.msappspace.com";
        requestObj.ConsumerKey = "http://www.myspace.com/346375750";
        requestObj.ConsumerSecret = "e42baa50e9694afcb95ab188ad2505e6";
        requestObj.RequestMethod = (HttpPostUtility.RequestMethod)Convert.ToInt32(DropDownList1.SelectedItem.Value);
        requestObj.RequestMode = HttpPostUtility.RequestMode.QueryString;
        requestObj.ResponseType = HttpPostUtility.ResponseType.XML;
        requestObj.Token = "";
        requestObj.TokenSecret = "";
        requestObj.UserId = "30344243";
        if (DropDownList1.SelectedItem.Value == "2")
        {
            requestObj.ResponsePageNumber = "1";
            requestObj.ResponsePageSize = "25";
            requestObj.ResponseListType = HttpPostUtility.MyspaceRequest.ListType.none;
        }

        switch (DropDownList1.SelectedItem.Value)
        {
            case "3":
                requestObj.AssetID = FriendId.Text;
                break;
            case "5":
                requestObj.AssetID = AlbumId.Text;
                break;
            case "6":
                requestObj.AssetID = AlbumId.Text;
                break;
            case "8":
                requestObj.AssetID = PhotoId.Text;
                break;
            case "12":
                requestObj.AssetID = VideoId.Text;
                break;
            default:
                requestObj.AssetID = "";
                break;
        }

        returnStr = poster.MakeRequest(requestObj);
        TextBox1.Text = returnStr;
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (DropDownList1.SelectedItem.Value)
        {
            case "3":
                ShowPanel(FriendIdPanel);
                break;
            case "5":
                ShowPanel(AlbumIdPanel);
                break;
            case "6":
                ShowPanel(AlbumIdPanel);
                break;
            case "8":
                ShowPanel(PhotoIdPanel);
                break;
            case "12":
                ShowPanel(VideoIdPanel);
                break;
            default:
                HideAllPanels();
                break;
        }
    }
    protected void ShowPanel(Panel panel1)
    {
        FriendIdPanel.Visible = false;
        AlbumIdPanel.Visible = false;
        PhotoIdPanel.Visible = false;
        VideoIdPanel.Visible = false;
        panel1.Visible = true;
    }
    protected void HideAllPanels()
    {
        FriendIdPanel.Visible = false;
        AlbumIdPanel.Visible = false;
        PhotoIdPanel.Visible = false;
        VideoIdPanel.Visible = false;
    }
}

